const Worktile = require("lib-worktile/lib").web.WorktileWeb;


/**
 * @returns {Promise<{ok:Boolean,msg:String}>}
 * @param {Worktile} wt 
 * @param {String} task_id 
 * @param {String} attachment_content 
 * @param {String} attachment_filename 
 */
function attachmentComment(wt, task_id, attachment_content, attachment_filename) {
  return new Promise(async resolve => {
    let o_up_attachment = await wt.__uploadStream(attachment_content, `${Date.now()}.${attachment_filename}`, "", true);
    if (!o_up_attachment.ok) {
      return resolve({
        ok: false,
        msg: `failed to upload attachment:${o_up_attachment.msg}`
      })
    }
    let o_comment = await wt.commentTask(task_id, attachment_filename, [o_up_attachment.data._id]);
    resolve({
      ok: o_comment.ok,
      msg: o_comment.msg
    })
  })
}


module.exports = {
  attachmentComment:attachmentComment
}